﻿/* Copyright (c) 2010 EPiServer AB
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
using System.Web.UI;
using System.Web.UI.WebControls;
using EPiServer.Configuration;
using EPiServer.Core;
using EPiServer.Web.PropertyControls;

namespace EPiServer.Municipality.Web.UI.PropertyControls {
    /// <summary>
    /// </summary>
    /// <remarks>
    /// </remarks>
    public class PropertyLongMainIntroControl : PropertyTextBoxControlBase {
        /* *******************************************************************
        *  Properties 
        * *******************************************************************/
        #region public override TableRowLayout RowLayout

        /// <summary>
        /// Gets the RowLayout of the PropertyMainIntroControl
        /// </summary>
        /// <value></value>
        public override TableRowLayout RowLayout {
            get { return TableRowLayout.Wide; }
        }

        #endregion

        /* *******************************************************************
        *  Methods 
        * *******************************************************************/
        #region public override void CreateEditControls()

        /// <summary>
        /// 
        /// </summary>
        public override void CreateEditControls() {
            EditControl = new TextBox
                              {
                                  MaxLength = 255,
                                  TextMode = TextBoxMode.MultiLine,
                                  Rows = 8,
                                  Width = Settings.Instance.UIEditorWidth - 10
                              };
            EditControl.Attributes.Add("style", "font: normal 13px Arial;");
            ApplyControlAttributes(EditControl);
            Controls.Add(EditControl);
            SetupEditControls();
        }

        #endregion
        #region public override void CreateDefaultControls()

        /// <summary>
        /// 
        /// </summary>
        public override void CreateDefaultControls() {
            Literal target = new Literal();
            target.Text = ToWebString().Replace("\n", "<br />");
            Controls.Add(target);
        }

        #endregion
        #region public override void RenderBeginTag(HtmlTextWriter writer)

        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        public override void RenderBeginTag(HtmlTextWriter writer) {
            if (AttributeSourceControl != null && !IsNull) {
                writer.WriteBeginTag("p");
                if (!string.IsNullOrEmpty(AttributeSourceControl.ControlStyle.CssClass))
                    writer.WriteAttribute("class", AttributeSourceControl.ControlStyle.CssClass);
                writer.Write(HtmlTextWriter.TagRightChar);
            }
        }

        #endregion
        #region public override void RenderEndTag(HtmlTextWriter writer)

        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        public override void RenderEndTag(HtmlTextWriter writer) {
            if (AttributeSourceControl != null && !IsNull)
                writer.WriteEndTag("p");
        }

        #endregion
    }
}